/*
 * MomberBan2Midlet.java
 * 
 *  author: Daniel Rudigier
 *    date: 02.12.2008
 * 
 * 
 */
package at.momberban2.me.game;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * @author Daniel Rudigier
 */
public class M2Midlet extends MIDlet {
    private static final M2ResourceManager MGR = (M2ResourceManager) M2ResourceManager
            .getInstance();

    private M2Game game = new M2Game();

    /**
     * constructor
     */
    public M2Midlet() {
        this.game.setName("MomberBan V2.0");
        
        // load some default settings
        MGR.loadConfiguration("/config/default.txt");
        MGR.loadLanguage("/language/English.txt");
        
        // load the map stubs
        MGR.loadMap("Classic 2vs2", "/maps/MapClassic2P.txt");
        MGR.loadMap("Classic 4vs4", "/maps/MapClassic4P.txt");

        ready();
    }

    /**
     * return for aspect advice. (constructor pointcut doesn't work here,
     * because the midlet instantiation is done somewhere else)
     */
    private M2Midlet ready() {
        return this;
    }

    /**
     * @return game
     */
    public M2Game getGame() {
        return game;
    }

    /**
     * override
     * 
     * @see javax.microedition.midlet.MIDlet#startApp()
     */
    protected void startApp() throws MIDletStateChangeException {
        // get advised
    }

    /**
     * override
     * 
     * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
     */
    protected void destroyApp(boolean unconditional)
            throws MIDletStateChangeException {
        // not used
        terminate(unconditional);
    }

    /**
     * override
     * 
     * @see javax.microedition.midlet.MIDlet#pauseApp()
     */
    protected void pauseApp() {
        // TODO Auto-generated method stub

    }
    
    /**
     * terminate the midlet
     * 
     * @param force
     */
    public void terminate(boolean force) {
        // if (this.pregameListener != null) {
        // this.pregameListener.disconnect();
        // Logger.log("all disconnected");
        // }

        if (force) {
            notifyDestroyed();
        }
    }

}
